function add_user_view() {
	$("#main-content-body").html("");
	$("#main-content-body").append("<p><label for='username' class='label'>用户名：</label><span><input type='text' name='username' id='username' style='height:33px; width:230px;' /></span><span style='width:20px; color:#F00; text-align:center;'>*</span><span>用户名长度6~20</span></p><br class='spacer' />");
    $("#main-content-body").append("<p><label for='password' class='label'>密码：</label><span><input type='password' name='password' id='password' style='height:33px; width:230px;' /></span><span style='width:20px; color:#F00; text-align:center;'>*</span><span>密码长度6~20</span></p><br class='spacer' />");
	$("#main-content-body").append("<p><label for='password2' class='label'>密码确认：</label><span><input name='password2' id='password2' type='password' style='height:33px; width:230px;' /></span><span style='width:20px; color:#F00; text-align:center;'>*</span><span></span></p><br class='spacer' />");
	$("#main-content-body").append("<p><span name='button' style='width:100px; margin-left:130px; cursor:pointer; background:#EEEEEE;'>添加</span></p> ");
	$("#main-content-body span[name='button']").bind("click", admin_add_user);
}

function admin_add_user() {
	var userName = $("#main-content-body input[name='username']").val();
	var password = $("#main-content-body input[name='password']").val();
	var password2 = $("#main-content-body input[name='password2']").val();
	if(userName.length<6||userName.length>20) {
		console.log("用户名长度不符合");
	} else if(password.length<6||password.length>20) {
		console.log("密码长度不符合");
	} else if(password!=password2) {
		console.log("两次密码不同");
	} else {
		$("#main-content-body span[name='button']").html("保存中...").css("cursor","text").unbind("click");
		$.post("add_user", { username: userName, password: password }, function() {
			$("#main-content-body span[name='button']").html("添加").css("cursor","pointer").bind("click", admin_add_user);
		});
	}
}

function query_user_page(pageNo) {
	var pageSize = 10;
	var pageCount;
	var msgArray;
	var resultArray;
	var dataArray;
	var rowCount;

	$.getJSON("query_user_page", {beginIndex:(pageNo-1)*pageSize,count:pageSize}, function(data) {
		msgArray = eval("("+data.msg+")");
		resultArray = msgArray.result;
		if(resultArray[0].resultMsg == "success") {
			rowCount = resultArray[0].rowCount;
			pageCount = Math.ceil(rowCount/pageSize);
			if(pageCount == 0) {
				pageCount = 1;
			}
			dataArray = msgArray.data;
			$("#main-content-body").html("");
			$("#main-content-body").append("<p><span class='cbox'><input type='checkbox'></input></span><span class='name'>用户名</span><span class='name'>真实姓名</span><span class='telephone'>电话</span><span class='qq'>QQ</span><span class='email'>E-mail</span><span class='liveLocation'>现居住地</span><span class='edit'>操作</span></p><hr class='spacer' />");
			$.each(dataArray, function(i, item) {
				$("#main-content-body").append("<p><span class='cbox'><input type='checkbox' value='"+item.id+"'></input></span><span class='name'>"+item.username+"</span><span class='name'>"+item.realname+"</span><span class='telephone'>"+item.telephone+"</span><span class='qq'>"+item.qq+"</span><span class='email'>"+item.email+"</span><span class='liveLocation'>"+item.liveLocation+"</span><span class='edit'><label>操作</label></span></p><br class='spacer' />");
			});
			$("#main-content-footer").html("<ul><li style='width:60px;'><span class='pageSelect' value='1'>首页</span></li><li style='width:60px;'><span class='pageSelect' value='"+parseInt(pageNo - 1) +"'>上一页</span></li><li style='width:60px;'><span class='pageSelect' value='"+parseInt(parseInt(pageNo) + 1) +"'>下一页</span></li><li style='width:60px;'><span class='pageSelect' value='"+pageCount+"'>末页</span></li><li>共<span>"+rowCount+"</span>条记录</li><li>每页"+pageSize+"条</li><li>当前<span>"+pageNo+"</span>/<span>"+pageCount+"</span>页</li></ul><br class='spacer' />");
			$("#main-content-footer .pageSelect").each(function() {
				$(this).click(function() {
					var tempPageNo = $(this).attr("value");
					if(tempPageNo>pageCount) {
						pageNo = pageCount;
					} else if(tempPageNo<1) {
						pageNo = 1;
					} else {
						query_user_page(tempPageNo);
					}
				});
			});
		} else {
			$("#main-content-body").html(resultArray[0].errorMsg);
		}
	});
}

function itemInfoDetail(infoId) {
	$("#info-item").fadeIn();
	$.get("queryById_user", {userId:$.trim(infoId)}, function(data){
		itemData = eval(data.msg)[0];
		$("#info-item .item-header h3").html(itemData.userName + " - 详细信息");
		$("#info-item .item-body").html("" +
			"<p><label>用户名</label><span editAble='false'>"+itemData.userName+"</span><label>真实姓名</label><span editAble='true'>"+itemData.userRealName+"</span></p>" +
			"<p><label>电话</label><span editAble='true'>"+itemData.userTelephone+"</span><label>QQ</label><span editAble='true'>"+itemData.userQq+"</span></p>" +
			"<p><label>E-mail</label><span editAble='true'>"+itemData.userEmail+"</span><label>出生日期</label><span editAble='true'>"+itemData.userBirthDate+"</span></p>" +
			"<p><label>证件号码</label><span style='width:500px;' editAble='true'>"+itemData.userIDCard+"</span></p>" +
			"<p><label>出生地</label><span style='width:500px;' editAble='true' birthLocationId='"+itemData.birthLocationId+"'>"+itemData.birthLocation+"</span></p>" +
			"<p><label>现居住地</label><span style='width:500px;' editAble='true' liveLocationId='"+itemData.liveLocationId+"' livePalce='"+itemData.userLivePlace+"'>"+itemData.liveLocation + " " + itemData.userLivePlace +"</span></p>" +
			"<p><label>注册时间</label><span style='width:500px;' editAble='false'>"+itemData.registerTime+"</span></p>");
		$("#info-item .item-footer").html("<span class='close'>关闭</span> | <span class='edit'>编辑</span> <span class='save'>保存</span>");
		
		$("#info-item .item-footer span.edit").click(function() {
			$("#info-item .item-body span[editAble='true']").each(function(index) {
				var nameValue=$(this).attr("name");
				var thisValue=$(this).html();
				$(this).html("<input type='text' name='"+nameValue+"' value='"+thisValue+"'></input>");
				//取位置信息
			});
			$("#info-item .item-footer span.edit").hide();
			$("#info-item .item-footer span.save").show().click(function() {
				$("#info-item .item-body span[editAble='true'] input").each(function() {
					$(this).parent().html($(this).val());
				});
				$("#info-item .item-footer span.save").hide();
				$("#info-item .item-footer span.edit").show();
			});
		});					
	});
}